home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / graphics / gnuplot / eval.c < prev    next >
C/C++ Source or Header  |  1993-09-15  |  4KB  |  168 lines

  1. #ifndef lint
  2. static char *RCSid = "$Id: eval.c%v 3.50 1993/07/09 05:35:24 woo Exp $";
  3. #endif
  4.  
  5.  
  6. /* GNUPLOT - eval.c */
  7. /*
  8.  * Copyright (C) 1986 - 1993   Thomas Williams, Colin Kelley
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted, 
  12.  * provided that the above copyright notice appear in all copies and 
  13.  * that both that copyright notice and this permission notice appear 
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed 
  18.  * as patches to released version.
  19.  *  
  20.  * This software is provided "as is" without express or implied warranty.
  21.  * 
  22.  *
  23.  * AUTHORS
  24.  * 
  25.  *   Original Software:
  26.  *     Thomas Williams,  Colin Kelley.
  27.  * 
  28.  *   Gnuplot 2.0 additions:
  29.  *       Russell Lang, Dave Kotz, John Campbell.
  30.  *
  31.  *   Gnuplot 3.0 additions:
  32.  *       Gershon Elber and many others.
  33.  * 
  34.  * There is a mailing list for gnuplot users. Note, however, that the
  35.  * newsgroup 
  36.  *    comp.graphics.gnuplot 
  37.  * is identical to the mailing list (they
  38.  * both carry the same set of messages). We prefer that you read the
  39.  * messages through that newsgroup, to subscribing to the mailing list.
  40.  * (If you can read that newsgroup, and are already on the mailing list,
  41.  * please send a message info-gnuplot-request@dartmouth.edu, asking to be
  42.  * removed from the mailing list.)
  43.  *
  44.  * The address for mailing to list members is
  45.  *       info-gnuplot@dartmouth.edu
  46.  * and for mailing administrative requests is 
  47.  *       info-gnuplot-request@dartmouth.edu
  48.  * The mailing list for bug reports is 
  49.  *       bug-gnuplot@dartmouth.edu
  50.  * The list of those interested in beta-test versions is
  51.  *       info-gnuplot-beta@dartmouth.edu
  52.  */
  53.  
  54. #include <stdio.h>
  55. #include "plot.h"
  56.  
  57. extern int c_token;
  58. extern struct ft_entry ft[];
  59. extern struct udvt_entry *first_udv;
  60. extern struct udft_entry *first_udf;
  61. extern struct at_type at;
  62. extern struct lexical_unit token[];
  63.  
  64. struct value *Ginteger();
  65.  
  66.  
  67.  
  68. struct udvt_entry *
  69. add_udv(t_num)  /* find or add value and return pointer */
  70. int t_num;
  71. {
  72. register struct udvt_entry **udv_ptr = &first_udv;
  73.  
  74.     /* check if it's already in the table... */
  75.  
  76.     while (*udv_ptr) {
  77.         if (equals(t_num,(*udv_ptr)->udv_name))
  78.             return(*udv_ptr);
  79.         udv_ptr = &((*udv_ptr)->next_udv);
  80.     }
  81.  
  82.     *udv_ptr = (struct udvt_entry *)
  83.       alloc((unsigned long)sizeof(struct udvt_entry), "value");
  84.     (*udv_ptr)->next_udv = NULL;
  85.     copy_str((*udv_ptr)->udv_name,t_num);
  86.     (*udv_ptr)->udv_value.type = INTGR;    /* not necessary, but safe! */
  87.     (*udv_ptr)->udv_undef = TRUE;
  88.     return(*udv_ptr);
  89. }
  90.  
  91.  
  92. struct udft_entry *
  93. add_udf(t_num)  /* find or add function and return pointer */
  94. int t_num; /* index to token[] */
  95. {
  96. register struct udft_entry **udf_ptr = &first_udf;
  97.  
  98.     int i;
  99.     while (*udf_ptr) {
  100.         if (equals(t_num,(*udf_ptr)->udf_name))
  101.             return(*udf_ptr);
  102.         udf_ptr = &((*udf_ptr)->next_udf);
  103.     }
  104.      *udf_ptr = (struct udft_entry *)
  105.       alloc((unsigned long)sizeof(struct udft_entry), "function");
  106.     (*udf_ptr)->next_udf = (struct udft_entry *) NULL;
  107.     (*udf_ptr)->definition = NULL;
  108.     (*udf_ptr)->at = NULL;
  109.     copy_str((*udf_ptr)->udf_name,t_num);
  110.     for(i=0; i<MAX_NUM_VAR; i++)
  111.         (void) Ginteger(&((*udf_ptr)->dummy_values[i]), 0);
  112.     return(*udf_ptr);
  113. }
  114.  
  115.  
  116. union argument *
  117. add_action(sf_index)
  118. enum operators sf_index;        /* index of p-code function */
  119. {
  120.     if (at.a_count >= MAX_AT_LEN)
  121.         int_error("action table overflow",NO_CARET);
  122.     at.actions[at.a_count].index = sf_index;
  123.     return(&(at.actions[at.a_count++].arg));
  124. }
  125.  
  126.  
  127. int standard(t_num)  /* return standard function index or 0 */
  128. {
  129. register int i;
  130.     for (i = (int)SF_START; ft[i].f_name != NULL; i++) {
  131.         if (equals(t_num,ft[i].f_name))
  132.             return(i);
  133.     }
  134.     return(0);
  135. }
  136.  
  137.  
  138.  
  139. execute_at(at_ptr)
  140. struct at_type *at_ptr;
  141. {
  142. register int i,index,count,offset;
  143.  
  144.     count = at_ptr->a_count;
  145.     for (i = 0; i < count;) {
  146.         index = (int)at_ptr->actions[i].index;
  147.         offset = (*ft[index].func)(&(at_ptr->actions[i].arg));
  148.         if (is_jump(index))
  149.             i += offset;
  150.         else
  151.             i++;
  152.     }
  153. }
  154.  
  155. /*
  156.  
  157.  'ft' is a table containing C functions within this program. 
  158.  
  159.  An 'action_table' contains pointers to these functions and arguments to be
  160.  passed to them. 
  161.  
  162.  at_ptr is a pointer to the action table which must be executed (evaluated)
  163.  
  164.  so the iterated line exectues the function indexed by the at_ptr and 
  165.  passes the address of the argument which is pointed to by the arg_ptr 
  166.  
  167. */
  168.